home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16983 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  64 lines

  1. X-ZC-POST: Amselweg 5; 45731 Waltrop
  2. X-ZC-TELEFON: +49-2309-920126
  3. X-Mailer: CrossPoint v3.11 R/C8604
  4. Message-ID: <66iHfO6PoYB@37.viking.ruhr.com>
  5. Organization: Ortwin Gasper
  6. X-Gateway: ZCONNECT UU viking.ruhr.com [DUUCP BETA vom 30.03.1996]
  7. References: <4kiai0$mjd@dfw-ixnews8.ix.netcom.com>
  8. From: gasper@viking.ruhr.com (Ortwin Gasper)
  9. Subject: Re: Why don't you use garbage collection
  10. Date: 12 Apr 1996 21:07:00 +0200
  11. Path: viking.ruhr.com!gasper
  12. Newsgroups: comp.lang.c++
  13. Distribution: world
  14.  
  15. > So, do you use garbage collection in your C/C++ programs, and if not,
  16. > why not?
  17.  
  18. Hi,
  19.  
  20. I see the following problems:
  21. - If you want to program 'normally' (as you would do without the presence
  22.   of a garbage collector), you can only choose a conservative one (see
  23.   Boehm et alii). In this case
  24.   - you must make assumptions on the compiler's behaviour.
  25.     (if for (i=1;i<x;i++) a[i] = b[i] is internally transformed to machine
  26.      code like (in C++-Syntax)
  27.      someoffset = a - b;
  28.      for (i=1;i<x;i++) b[i-someoffset] = b[i]   // ***
  29.      a = b + someoffset,
  30.      garbage collection at the time of the loop, possibly caused by
  31.      another thread, could reclaim a incorrectly)
  32.   - you must accept, that the percentage of not reclaimed memory isn't
  33.     bounded. (In Boehms collector an integer variable could hold for
  34.     long times a value that (interpreted as a pointer) is a root to a
  35.     very long chain of garbage.)
  36.   In the real world these problems have no significance. But the problem
  37.   of memory fragmentation remains.
  38. - If you want that a program never fails if the amount of needed memory m
  39.   is <= C*n with n = the available memory and C a constant 0 < C <= 1, you
  40.   must use copying collectors. But in this case, you can't program in
  41.   'normal' C++. You must remember the position of all pointers to the
  42.   collected area, you must handle problems like 'what happens if the
  43.   collector moves a class object while there is a stack frame from a
  44.   member function of this object still valid'.
  45.   ==> You can write C++-Programs using such a collector, but these
  46.   programs won't look like C++, are hard to debug (and slow).
  47.  
  48. The only portable solution I see is:
  49. Integrate garbage collection as an optional feature in the language and  
  50. let the compiler do all the work for you. There could be a keyword like
  51. moveable, and rules like 'union { moveable * x; int y }' is not allowed.
  52. If this is done, everybody can work with well debugged collectors in a  
  53. natural way. Programming becomes easier and more safe.
  54.  
  55. Regards
  56.  
  57.         Ortwin
  58.  
  59.  
  60.  
  61.  
  62.  
  63. ## CrossPoint v3.11 R ##
  64.